/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduValidateQuestion;
import com.xci.edu.core.filter.EduValidateQuestionFilter;
import com.xci.edu.core.service.EduValidateQuestionService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学习验证问题接口
 * @author 吕艳阳 lvyanyang@xci96716.com
 * @since 2020-11-24 10:19:12
 */
@Api(tags = "学习验证问题接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/eduValidateQuestion", produces = Const.PROJSON)
public class EduValidateQuestionApiController extends BaseController {
    /** 验证问题服务 */
    @Resource private EduValidateQuestionService eduValidateQuestionService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建验证问题")
    //@Authorize(code = "core.eduValidateQuestion.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody EduValidateQuestion entity) {
        return eduValidateQuestionService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改验证问题")
    //@Authorize(code = "core.eduValidateQuestion.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody EduValidateQuestion entity) {
        return eduValidateQuestionService.update(entity);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除验证问题")
    //@Authorize(code = "core.eduValidateQuestion.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return eduValidateQuestionService.delete(body.getIds());
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "检查验证问题名称是否存在")
    @PostMapping(value = "/existByName")
    public BoolResult existByName(@RequestBody NameExcludeIdBody body) {
       return BoolResult.success(eduValidateQuestionService.existByName(body.getName(), body.getExcludeId()));
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据主键查询单个验证问题")
    //@Authorize(code = "core.eduValidateQuestion.select")
    @PostMapping("/selectById")
    public BoolResult<EduValidateQuestion> selectById(@RequestBody IdBody body) {
        return BoolResult.success(eduValidateQuestionService.selectById(body.getId()));
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "查询验证问题分页列表")
    //@Authorize(code = "core.eduValidateQuestion.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<EduValidateQuestion>> selectPageList(@RequestBody EduValidateQuestionFilter filter) {
        return BoolResult.success(eduValidateQuestionService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询验证问题列表")
    //@Authorize(code = "core.eduValidateQuestion.select")
    @PostMapping("/selectList")
    public BoolResult<List<EduValidateQuestion>> selectList(@RequestBody EduValidateQuestionFilter filter) {
        return BoolResult.success(eduValidateQuestionService.selectList(filter));
    }

    @ApiOperationSupport(order = 11, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出验证问题列表")
    //@Authorize(code = "core.eduValidateQuestion.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody EduValidateQuestionFilter filter) {
        XCI.exportExcel(eduValidateQuestionService.selectList(filter), EduValidateQuestion.class, "验证问题列表");
    }
}